<template>
    <div class="qingwu">
        <div class="admin_table_page_title">业主列表</div>
        <div class="unline underm"></div>

        <div class="admin_table_handle_btn">
            <a-form layout="inline" :form="form"  @submit="handleSubmit">
                <a-form-item label="业主名称">
                    <a-input v-model="truename"  />
                </a-form-item>
                <a-form-item label="手机号">
                    <a-input v-model="mobile"  />
                </a-form-item>
                <a-form-item label="小区">
                    <a-select  @change="handleChange" style="width: 120px" default-value="请选择小区" v-model="community_id" >
                        <a-select-option value="">请选择小区</a-select-option>
                        <a-select-option  :value="value.id" v-for="(value,index) in community_lists" :key="index">
                            {{ value.name }}
                        </a-select-option>
                    </a-select>
                </a-form-item>
                <a-form-model-item >
                    <a-button icon="search" @click="search">
                        查询
                    </a-button>
                </a-form-model-item>
                <a-form-model-item >
                    <a-button  @click="reset">重置</a-button>
                </a-form-model-item>
            </a-form>
        </div>

        <div class="admin_table_handle_btn">
            <a-button @click="$router.push('/Estate/platform_owner/form')" type="primary" icon="plus">添加</a-button>
            <a-button class="admin_delete_btn" type="danger" icon="delete" @click="dels">批量删除</a-button>
        </div>
        <div class="admin_table_list">
            <a-table :columns="columns" :data-source="list" :pagination="false" :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }" row-key="id">



                <div slot="userdata" slot-scope="rows">
                    <p>姓名: {{rows.truename}}</p>
                    <p>手机号: {{rows.mobile}}</p>
                    <p>身份证号: {{rows.id_number}}</p>
                </div>
                <div slot="communitydata" slot-scope="rows">
                    <p>区域名称: {{rows.community_data ? rows.community_data.name: '' }}
                    </p>
                    <p>分区名称: {{rows.community_areas_data ? rows.community_areas_data.area_name : ""}}</p>
                    <p>房间信息: {{rows.room_number}}</p>
                    <p>住房面积: {{rows.housing_area}}</p>
                    <p>套内面积: {{rows.inner_area}}</p>
                </div>
                <div slot="facilitydata" slot-scope="rows">
                    <p>电表: <span>{{rows.elc_code}}</span></p>
                    <p>水表: <span>{{rows.water_code}}</span></p>
                </div>
                <div slot="balancedata" slot-scope="rows">
                    <p>电费: <span>{{rows.electricity_bill_balance}}</span></p>
                    <p>水费: {{rows.water_bill_balance}}</p>
                    <p>物业费: {{rows.property_bill_balance}}</p>
                </div>


                <span slot="action" slot-scope="rows">
                    <a-button size="small" icon="edit" @click="$router.push('/Estate/platform_owner/form/'+rows.id)">编 辑</a-button>
                    <a-button size="small" icon="edit" @click="del(rows.id)">删 除</a-button>
                    <a-button size="small" icon="edit" @click="$router.push('/Admin/users/form/'+rows.id)">电表订单</a-button>
                    <br>
                    <a-button size="small" icon="edit" @click="$router.push('/Admin/users/form/'+rows.id)">水表订单</a-button>
                    <a-button size="small" icon="edit" @click="$router.push('/Admin/users/form/'+rows.id)">缴费记录</a-button>
                    <a-button size="small" icon="edit" @click="$router.push('/Admin/users/form/'+rows.id)">账单记录</a-button>
                </span>

                <span slot="status" slot-scope="rows">
                    <a-switch v-if="rows.status == 1" checked-children="正常" un-checked-children="禁用" @change="onChangeStatus('status', rows.id)" default-checked/>
                    <a-switch v-else checked-children="正常" @change="onChangeStatus('status', rows.id)" un-checked-children="禁用" />
                </span>
            </a-table>
            <div class="admin_pagination" v-if="total>0">
                <a-pagination v-model="params.page" :page-size.sync="params.per_page" :total="total" @change="onChange" show-less-items />
            </div>
        </div>
    </div>
</template>

<script>
export default {
    components: {},
    props: {},
    data() {
      return {
          params:{
              page:1,
              per_page:30,
          },
          total:0, //总页数
          selectedRowKeys:[], // 被选择的行
          columns:[
              {title:'#',dataIndex:'id',fixed:'left'},
              {title:'业主信息',scopedSlots: { customRender: 'userdata' }},
              {title:'区域信息',scopedSlots: { customRender: 'communitydata' }},
              {title:'设备信息',scopedSlots: { customRender: 'facilitydata' }},
              {title:'余额信息',scopedSlots: { customRender: 'balancedata' }},
              {title: '状态', scopedSlots: { customRender: 'status' }},
              {title:'创建时间',dataIndex:'create_time'},
              {title:'操作',key:'id',fixed:'right',scopedSlots: { customRender: 'action' }},
          ],
          list:[],
          truename:'',  // 名称
          phone:'',     // 手机号
          community_id:'',   // 小区ID
          community_lists: []
      };
    },
    watch: {},
    computed: {},
    methods: {
        // 选择框被点击
        onSelectChange(selectedRowKeys) {
            this.selectedRowKeys = selectedRowKeys;
        },
        // 选择分页
        onChange(e){
            this.params.page = e;
            this.onload();
        },
        // 删除
        del(id){

            this.$confirm({
                title: '你确定要删除选择的数据？',
                content: '确定删除后无法恢复.',
                okText: '是',
                okType: 'danger',
                cancelText: '取消',
                onOk:()=> {
                    this.$get(this.$api.editPlatformOwnerDel+'/'+id).then(res=>{
                        if(res.code == 200){
                            this.onload();
                            this.$message.success('删除成功');
                        }else{
                            this.$message.error(res.msg)
                        }
                    });

                },
            });
        },
        onload(){
            this.$get(this.$api.estatePlaformowner,this.params).then(res=>{
                this.total = res.data.total;
                this.list = res.data.data;
            });
        },
        // 重置
        reset(){
            location.reload();
        },
        // 获取小区列表
        getCommunityList(){
            this.$get(this.$api.getCommunity).then(res=>{
                this.community_lists = res.data;
            })
        },
        // 修改状态
        onChangeStatus(type,id){
            this.$post(this.$api.editPlaformownerStatus,{type:type,id:id}).then(res=>{
                if(res.code == 200){
                    this.$message.success(res.msg)

                }else{
                    return this.$message.error(res.msg)
                }

                this.onload();
            })
        },

        // 删除
        dels(){
            if(this.selectedRowKeys.length==0){
                return this.$message.error('未选择数据.');
            }
            this.$confirm({
                title: '你确定要删除选择的数据？',
                content: '确定删除后无法恢复.',
                okText: '是',
                okType: 'danger',
                cancelText: '取消',
                onOk:()=> {
                    let ids = this.selectedRowKeys.join(',');
                    this.$get(this.$api.editPlatformOwnerDel+'/'+ids).then(res=>{
                        if(res.code == 200){
                            this.onload();
                            this.$message.success('删除成功');
                        }else{
                            this.$message.error(res.msg)
                        }
                    });

                },
            });
        },
        // 搜索
        search(){
            this.params['truename'] = this.truename;
            this.params['mobile'] = this.phone;
            this.params['id'] = this.community_id;
            this.$get(this.$api.estatePlaformowner,this.params).then(res=>{
                this.total = res.data.total;
                this.list = res.data.data;
            });
        },
    },
    created() {
        this.onload();
        this.getCommunityList();/**/
    },
    mounted() {}
};
</script>
<style lang="scss" scoped>

</style>
